#include "one_card.h"
#include "cli.h"

#ifdef USE_GUI
#include "gui.h"
#endif

int main(int argc, char *argv[]) {
    struct args args = args_read(argc, argv);
    srand(args.seed);
    disp_welcome(), log_welcome(args.log_filep);
    disp_args(args), log_args(args.log_filep, args);

    struct player players[args.n];
    for (int i = 0; i < args.n; i++) {
        player_init(&players[i]);
        players[i].id = i;
    }
    players[0].neighbour[0] = &(players[args.n - 1]);
    for (int i = 1; i < args.n; i++) players[i].neighbour[0] = &(players[i - 1]);
    players[args.n - 1].neighbour[1] = &(players[0]);
    for (int i = 0; i < args.n - 1; i++) players[i].neighbour[1] = &(players[i + 1]);

    struct board board;
    board_init(&board, args);

    if (args.use_GUI) {
#ifdef USE_GUI
        gui_main(players, &board, args);
#endif
    } else {
        cli_main(players, &board, args);
    }

    board_destroy(&board);
    for (int i = 0; i < args.n; i++) player_destroy(players + i);
    fclose(args.log_filep);
    return 0;
}
